﻿
@{
    Layout = "~/Views/Shared/_LayoutNoBody.cshtml";
}

<body class="hold-transition login-page login_bg">
    <div class="login-box">
        <div class="login-logo">
            <a href="#">@ViewData["SoftName"]</a>
        </div>
        <!-- /.login-logo -->
        <div class="card">
            <div class="card-body login-card-body">
                <div class="form-group has-feedback">
                    <img src="@ViewData["Logo"]" />
                </div>
                <form action="#" method="post">
                    <div class="form-group has-feedback">
                        <input type="text" id="userName" class="form-control" placeholder="用户名">
                    </div>
                    <div class="form-group has-feedback">
                        <input type="password" id="password" class="form-control" placeholder="密码">
                    </div>
                    <div class="row">
                        <div class="col-8">
                            <div class="checkbox icheck">
                                <label>
                                    <input type="checkbox" id="rememberMe"> 记住我
                                </label>
                            </div>
                        </div>
                        <!-- /.col -->
                    </div>
                    <div class="row">
                        <button id="login_button" class="btn btn-primary btn-block" type="button" onclick="login()"><span>登录</span></button>
                    </div>

                    <div class="row">
                    </div>
                </form>
                <p class="login-box-msg" id="login-box-msg"></p>
            </div>
            <!-- /.login-card-body -->
        </div>
    </div>
    <div id="footer" class="footer " role="contentinfo">
        <div class="footerNodelf text-secondary">
            <span>本软件使用权属于：@ViewData["CertificatedCompany"]</span>
        </div>
        <div class="footerNode text-secondary">
            <span>@Html.Raw(ViewData["Copyriht"])</span>
        </div>
    </div>

    <script>
        $(function () {
            $('input').iCheck({
                checkboxClass: 'icheckbox_square-blue',
                radioClass: 'iradio_square-blue',
                increaseArea: '20%' // optional
            })


            //判断之前是否有设置cookie，如果有，则设置【记住我】选择框
            if ($.cookie("yuebon_login_username") != undefined) {
                $("#rememberMe").attr("checked", "checked");
            }
            else {
                $("#rememberMe").removeAttr("checked");
            }
            //读取cookie
            if ($("#rememberMe:checked").length > 0) {
                $("#userName").val($.cookie("yuebon_login_username"));
                $("#password").val($.cookie("yuebon_login_password"));
            }
        })

        function login() {
            if ($("#rememberMe:checked").length > 0) {//设置cookie
                $.cookie("yuebon_login_username", $("#userName").val());
                $.cookie("yuebon_login_password", $("#password").val());
            } else {//清除cookie
                $.removeCookie("yuebon_login_username");
                $.removeCookie("yuebon_login_password");
            }
            $.ajax({
                url: "/Login/GetCheckUser?username=" + $("#userName").val() + "&password=" + $("#password").val(),
                data: "",
                dataType: 'json',//服务器返回json格式数据
                type: 'get',//HTTP请求类型
                timeout: 50000,//超时时间设置为10秒；
                success: function (data) {
                    //服务器返回响应，根据响应结果，分析是否登录成功；
                    if (!data.Success) {
                        $("#login-box-msg").html(data.ErrMsg);
                    } else {
                        //var userinfo = data.ResData;
                        //$.cookie("", userinfo.Account, { expires: 7 });
                        //$.cookie("yuebon_login_realname", userinfo.RealName, { expires: 7 });
                        $("#login_button").find('span').html("登录成功，正在跳转...");
                        var redirect_uri = getQueryString("redirect_uri");
                        if (redirect_uri==null) {
                            redirect_uri = "/Home/Index";
                        }
                        window.setTimeout(function () {
                            window.location.href = redirect_uri;
                        }, 500);
                    }
                },
                error: function (data) {
                    $("#login-box-msg").html("登录异常，请重新试试");
                }
            })
        }
        function getQueryString(name) {
            var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i');
            var r = window.location.search.substr(1).match(reg);
            if (r != null) {
                return unescape(r[2]);
            }
            return null;
        }
    </script>
</body>